package com.ruoyi.machine.advanced.status.service;

import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.machine.advanced.status.domain.Status;
import com.ruoyi.machine.advanced.status.domain.StatusCond;
import com.ruoyi.machine.advanced.status.mapper.StatusMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 设备状态信息
 * 业务层处理
 */
@Service
public class StatusServiceImpl implements IStatusService{

    @Autowired
    private StatusMapper statusMapper;

    /**
     * 查找设备状态信息
     * @param status
     * @return
     */
    @Override
    public List<Status> selectStatusList(StatusCond status) {
        return statusMapper.selectStatusList(status);
    }

    /**
     * 根据Id查找设备状态信息
     * @param machineId
     * @return
     */
    @Override
    public Status selectStatusById(String machineId) {
        return statusMapper.selectStatusById(machineId);
    }

//    @Override
//    public int insertStatus(Status status) {
//        return statusMapper.insertStatus(status);
//    }

    @Override
    public int updateStatus(Status status) {
        if (!StringUtils.isNotNull(statusMapper.selectStatusById(status.getMachineId()))) {
            //存在
            return 0;
        }
//        webSocket.sendMessage(status.getMachineId());
        return statusMapper.updateStatus(status);
    }
}
